Skip to content

Fix/gemini cloud tool calling#15

Merged
PTFOPlayer merged 2 commits into
masterfrom
fix/gemini-cloud-tool-calling
May 25, 2026
Merged

Fix/gemini cloud tool calling#15
PTFOPlayer merged 2 commits into
masterfrom
fix/gemini-cloud-tool-calling

Conversation

@PTFOPlayer
Copy link
Copy Markdown
Owner

@PTFOPlayer PTFOPlayer commented May 25, 2026

This PR fixes tool calling with ollama cloud gemini 3 flash preview model

ollama-rs 0.3.4 serializes ToolType::Function as "Function" (uppercase F),
but Ollama Cloud / Gemini strictly requires lowercase "function" per the
API spec. This caused HTTP 400 errors: "Invalid tool type".

Also add the missing "name" field to "role: tool" messages, which
Gemini requires to match tool results back to tool calls.

Both fixes are applied as JSON post-processing in stream_ollama_chat()
just before sending the HTTP request, avoiding changes to data structures.
Three fixes for Ollama Cloud / Gemini compatibility:

1. Tool type casing: ollama-rs 0.3.4 serializes ToolType::Function as
   "Function" (uppercase F), but Gemini requires lowercase "function".
   Post-process request JSON to normalize it.  Fixes "Invalid tool type".

2. Missing 'name' on tool messages: Gemini requires the 'name' field on
   'role: tool' messages to match results to calls. Inject it from the
   preceding assistant message's tool_calls.

3. Missing thought_signature: Gemini requires a thought_signature on
   function call parts in multi-turn tool calling. ollama-rs drops this
   field.  Capture it from raw SSE response JSON (via OllamaChunk) and
   store it in ToolCallFunction.thought_signature.  Re-inject it in
   follow-up requests via fix_request_json.

Added ToolCallFunction.thought_signature: Option<String> to the shared
provider types (with serde(skip_serializing_if = Option::is_none)).
@PTFOPlayer PTFOPlayer merged commit 2ad7244 into master May 25, 2026
4 checks passed
@PTFOPlayer PTFOPlayer deleted the fix/gemini-cloud-tool-calling branch June 4, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant